package com.joey.concurrency.example.singleton;

import com.joey.concurrency.annotation.Recommend;
import com.joey.concurrency.annotation.ThreadSafe;

/**
 * 枚举模式
 * @Author hyy
 **/
@ThreadSafe
@Recommend
public class SingtonExample5 {
    private SingtonExample5(){}

    public static SingtonExample5 getInstance(){
        return Singleton.INSTANCE.getInstance();
    }

    private enum Singleton {
        INSTANCE;
        private SingtonExample5 singtonExample5;
        //JVM保证这个方法绝对调用一次
        Singleton(){
            singtonExample5 = new SingtonExample5();
        }
        public SingtonExample5 getInstance(){
            return singtonExample5;
        }
    }
}
